{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'indices'|trans }} - {{ index.name }} - {{ 'lifecycle'|trans }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'indices'|trans, 'link': {'url': path('indices')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': index.name, 'badge': {'title': index.health|trans, 'context': index.health}}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/index/index_read_tabs.html.twig' with {'active': 'lifecycle'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'lifecycle'|trans}) }}

            {% if is_granted('INDEX_UPDATE', index) and true == lifecycle['managed'] %}
                {% embed 'Embed/buttons_embed.html.twig' %}
                    {% import 'Import/app_import.html.twig' as appImport %}
                    {% block content %}
                        {{ appImport.buttonModal({
                            'id': 'IndexRemovePolicy',
                            'title': 'remove_policy'|trans,
                            'body': lifecycle['policy'],
                            'href': path('indices_remove_policy', {'index': index.name}),
                        }) }}
                    {% endblock %}
                {% endembed %}
            {% endif %}

            <hr>

            <div class="row">
                {{ appImport.dashboardKpi({'title': 'managed'|trans, 'badge': {'title': ('boolean.' ~ lifecycle['managed'])|trans, 'context': lifecycle['managed']}}) }}

                {% if true == lifecycle['managed'] %}
                    {% if is_granted('ILM_POLICIES_LIST', 'ilm_policy') %}
                        {{ appImport.dashboardKpi({'title': 'ilm_policy'|trans, 'badge': {'title': lifecycle['policy'], 'link': path('ilm_read', {'name': lifecycle['policy']})}}) }}
                    {% else %}
                        {{ appImport.dashboardKpi({'title': 'ilm_policy'|trans, 'badge': {'title': lifecycle['policy']}}) }}
                    {% endif %}
                {% endif %}
            </div>

            {% if true == lifecycle['managed'] %}
                <pre>{{ lifecycle|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
            {% endif %}
        {% endblock %}
    {% endembed %}
{% endblock %}
